#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include "testutils.h"

test_playCard(void)
{
	int i, j;
	int handPos;
	int choice1, choice2, choice3;
	int result;
	int tmp;
	int prev_actions;
	struct gameState state;

	init_test_data(&state, num_players);

	srand(time(NULL));

	for (i = 0; i < NUM_ITERATIONS; i++) {
		for (j = 0; j < 10; j++) {
			state.hand[0][j] = rand_card();
		}

		state.handCount[0] = 10;

		do {
			handPos = rand() % 9;
		} while (!state.hand[0][handPos] > 7);

		choice1 = rand() % state.handCount[0]; 
		choice2 = rand() % state.handCount[0];
		choice3 = rand() % state.handCount[0];

		state.numActions = rand() % 4;
		state.phase = rand() % 2 - 1;

		prev_actions = state.numActions;

		result = playCard(handPos, choice1, choice2, choice3, &state);
		if (result > 0) {
			assert(state.numActions == prev_actions);

			// hmmmm....not sure how to check state here
		}
		else {
			tmp = handCard(handPos, &state);
			if (cardEffect(tmp, choice1, choice2, choice3, &state, handPos, NULL) < 0) {
				// okay
			} else {
				assert(state.phase != 0 || state.numActions < 1 || 
					    tmp < adventurer || tmp > treasure_map);
			}
		}
	}
}

int main(int argc, char const *argv[])
{
	test_playCard();
	return 0;
}